﻿using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.XtraBars;
using DevExpress.XtraEditors.ColorWheel;
using DevExpress.XtraNavBar;

namespace WinForm.Win
{
    public partial class FormMain : WinForm.MainForm
    {
        internal BarButtonItem AddButton { get { return bbiAdd; } }
        internal BarButtonItem EditButton { get { return bbiEdit; } }
        internal BarButtonItem DeleteButton { get { return bbiDelete; } }
        internal BarButtonItem PrevButton { get { return bbiPrev; } }
        internal BarButtonItem NextButton { get { return bbiNext; } }
        internal BarButtonItem RefreshButton { get { return bbiRefresh; } }

        //internal BarButtonItem SaveButton { get { return bbiSave; } }
        //internal BarButtonItem SaveAndCloseButton { get { return bbiSaveAndClose; } }
        //internal BarButtonItem CloseButton { get { return bbiClose; } }
        //internal BarButtonItem CloseDetailsButton { get { return bbiCloseDetails; } }
        //internal BarButtonItem HomeButton { get { return bbiHome; } }
        public FormMain()
        {
            InitializeComponent();
            this.Icon = ImagesHelper.AppIcon;
        }

        private void bbiColorMix_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ColorWheelForm form = new ColorWheelForm();
            form.StartPosition = FormStartPosition.CenterParent;
            form.SkinMaskColor = UserLookAndFeel.Default.SkinMaskColor;
            form.SkinMaskColor2 = UserLookAndFeel.Default.SkinMaskColor2;
            form.ShowDialog(this);
        }

        /// <summary>
        /// NavBar的链接改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void nbMain_SelectedLinkChanged(object sender, DevExpress.XtraNavBar.ViewInfo.NavBarSelectedLinkChangedEventArgs e)
        {
            if (e.Link == null) return;
            //todo: 需要先完成数据的保存，然后才能切换模块
            //if (ModulesInfo.Instance.CurrentModuleBase.TModule.AllowModuleChange)
            //{
            //    ShowModule(e.Link.Caption);
            //    prevLink = e.Link;
            //}
            //else
            //{
            //    nbMain.SelectedLink = prevLink;
            //}
            FunctionModules.Instance.ShowModule(this, this.UserControlContainer, e.Link.Caption, null);
        }
        /// <summary>
        /// NavBar的单击链接事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void nbMain_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            //todo: 需要先完成数据的保存，然后才能切换模块
            //if (ModulesInfo.CurrentModule == null || e.Link == null) return;
            //ModuleInfo info = e.Link.Item.Tag as ModuleInfo;
            //if (info == null) return;
            //if (ModulesInfo.CurrentModule.Name == info.TypeName)
            //    ModulesInfo.CurrentModule.ShowMasterModule();
            FunctionModules.Instance.ShowModule(this, this.UserControlContainer, e.Link.Caption, null);
            //FunctionModule clickedModule = FunctionModules.Instance[e.Link.Caption];
            //var thisForm = this as Form;
            //clickedModule.ShowInPanel(thisForm, this.MainContainer,@"nihao", null);
        }

        private void bbiAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //1.创建新的实体
            var newContact = new Model.Contacts()
            {
                City = "郑州市",
                PersonName = "邓乐",
                CellPhone = "185",
                TellPhone = "0371-67882008",
                Memo="信息科长"
            };

            //2.增加
           DAL.Contacts.Add(newContact);

        }
    }
}
